local skel = fk.CreateSkill{
    name = "ksp__yanfan",
}

Fk:loadTranslationTable{
  ["ksp__yanfan"] = "燕返",
  [":ksp__yanfan"] = "你使用的【杀】可结算两次，其中一次「无伤」，其中一次「致命」。",
  ["ksp__yanfan_ask1"] = "你使用的【杀】可结算两次，第一次「无伤」，第二次「致命」",
  ["ksp__yanfan_ask2"] = "你使用的【杀】可结算两次，第一次「致命」，第二次「无伤」",
  ["@@ksp__yanfan-phase"] = "燕返",

  ["$ksp__yanfan1"] = "石火春雷……一刀にて証を示す。",
  ["$ksp__yanfan2"] = "秘剣───燕返し！",
}

skel:addEffect(fk.PreCardUse,{--选效果
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and data.from == player and
    data.card.trueName == "slash"
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local chos = {"ksp__yanfan_ask1","ksp__yanfan_ask2","Cancel"}
    local chooce = room:askToChoice(player,{
      choices = chos,
      skill_name = skel.name,
    })
    if chooce == chos[1] then
      event:setCostData(self,{choose = 5})
      return true
    elseif chooce == chos[2] then
      event:setCostData(self,{choose = 6})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    data.card.skillName = skel.name
    player.room:setPlayerMark(player,"ksp__yanfan-phase",event:getCostData(self).choose)
  end,
})

skel:addEffect(fk.TargetSpecified,{--给目标加标记
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and
    data.card.trueName == "slash" and data.card.skillName == skel.name and player:getMark("ksp__yanfan-phase") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(data.to,"@@ksp__yanfan-phase",player:getMark("ksp__yanfan-phase"))
    data.use.additionalEffect = 1
  end,
})

skel:addEffect(fk.PreCardEffect,{--第一张杀和第二张杀的标记计算
  can_refresh = function(self, event, target, player, data)
    return player == target and data.card and data.card.skillName == skel.name and data.to:getMark("@@ksp__yanfan-phase") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(data.to,"@@ksp__yanfan-phase",-2)
  end,
})

skel:addEffect(fk.DamageCaused, {--造成伤害，但其实是受到伤害
  can_refresh = function(self, event, target, player, data)
    return player == target and data.card and data.card.skillName == skel.name and data.to:getMark("@@ksp__yanfan-phase") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local n = data.to:getMark("@@ksp__yanfan-phase")
    local add = data.to.hp + data.to.shield - data.damage
    if n == 4 then
      --第一次致命，第二次无伤
      data:changeDamage(add)
    elseif n ==3 then
      --第一次无伤，第二次致命
      data:preventDamage()
    elseif n == 2 then
      --第二次无伤
      data:preventDamage()
    elseif n == 1 then
      --第二次致命
      data:changeDamage(add)
    else
    end
  end,
})

skel:addEffect(fk.CardUseFinished,{--清标记
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player == data.from and
    data.card and data.card.skillName == skel.name
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    for _,p in ipairs(room:getAlivePlayers()) do
      room:setPlayerMark(p,"@@ksp__yanfan-phase",0)
      room:setPlayerMark(p,"ksp__yanfan-phase",0)
    end
  end,
})

return skel